<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="ROS1教程 1：ROS1安装, python,machine learning,deep learning,html,css,c,c++,cpp,cmake,ros,linux,ubuntu">
    <meta name="description" content="本文是ROS1系列教程的第一篇文章，介绍了如何安装ROS1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="referrer" content="no-referrer-when-downgrade">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>ROS1教程 1：ROS1安装 | JackWang&#39;s Blog</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery-3.6.0.min.js"></script>

<meta name="generator" content="Hexo 5.4.2">
<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css">
<link rel="stylesheet" href="/css/prism-line-numbers.css" type="text/css"></head>



   <style>
    body{
       background-image: url(https://cdn.jsdelivr.net/gh/Tokisaki-Galaxy/res/site/medias/background.jpg);
       background-repeat:no-repeat;
       background-size: 100% 100%;
       background-attachment:fixed;
    }
</style>



<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">JackWang&#39;s Blog</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="" class="waves-effect waves-light">

      
      <i class="fas fa-book-reader" style="zoom: 0.6;"></i>
      
      <span>博客</span>
      <i class="fas fa-chevron-down" aria-hidden="true" style="zoom: 0.6;"></i>
    </a>
    <ul class="sub-nav menus_item_child ">
      
      <li>
        <a href="/tags">
          
          <i class="fas fa-tags" style="margin-top: -20px; zoom: 0.6;"></i>
          
	  <span>按标签归类文章</span>
        </a>
      </li>
      
      <li>
        <a href="/categories">
          
          <i class="fas fa-bookmark" style="margin-top: -20px; zoom: 0.6;"></i>
          
	  <span>按目录归类文章</span>
        </a>
      </li>
      
      <li>
        <a href="/archives">
          
          <i class="fas fa-archive" style="margin-top: -20px; zoom: 0.6;"></i>
          
	  <span>按日期分类文章</span>
        </a>
      </li>
      
    </ul>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>



<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">JackWang&#39;s Blog</div>
        <div class="logo-desc">
            
            JackWang的个人博客
            
        </div>
    </div>

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="javascript:;">
			
				<i class="fa-fw fas fa-book-reader"></i>
			
			博客
			<span class="m-icon"><i class="fas fa-chevron-right"></i></span>
		</a>
            <ul  style="background:  ;" >
              
                <li>

                  <a href="/tags " style="margin-left:75px">
				  
				   <i class="fa fas fa-tags" style="position: absolute;left:50px" ></i>
			      
                              <span>按标签归类文章</    span>

                  </a>
                </li>
              
                <li>

                  <a href="/categories " style="margin-left:75px">
				  
				   <i class="fa fas fa-bookmark" style="position: absolute;left:50px" ></i>
			      
                              <span>按目录归类文章</    span>

                  </a>
                </li>
              
                <li>

                  <a href="/archives " style="margin-left:75px">
				  
				   <i class="fa fas fa-archive" style="position: absolute;left:50px" ></i>
			      
                              <span>按日期分类文章</    span>

                  </a>
                </li>
              
            </ul>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        
    </ul>
</div>


        </div>

        
    </nav>

</header>

    
<script src="/libs/cryptojs/crypto-js.min.js"></script>
<script>
    (function() {
        let pwd = '';
        if (pwd && pwd.length > 0) {
            if (pwd !== CryptoJS.SHA256(prompt('抱歉，这篇文章并不想让所有人都看到，请输入授权密码观看')).toString(CryptoJS.enc.Hex)) {
                alert('密码错误，将返回主页！');
                location.href = '/';
            }
        }
    })();
</script>




<div class="bg-cover pd-header post-cover" style="background-image: url('https://jack-1307599355.cos.ap-shanghai.myqcloud.com/%E5%B1%8F%E5%B9%95%E5%BD%95%E5%88%B62022-12-23%20%E4%B8%8B%E5%8D%881.50.16.gif')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">ROS1教程 1：ROS1安装</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/ROS1/">
                                <span class="chip bg-color">ROS1</span>
                            </a>
                        
                            <a href="/tags/ROS1%E6%95%99%E7%A8%8B/">
                                <span class="chip bg-color">ROS1教程</span>
                            </a>
                        
                            <a href="/tags/ROS1%E5%AE%89%E8%A3%85/">
                                <span class="chip bg-color">ROS1安装</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/ROS1%E6%95%99%E7%A8%8B/" class="post-category">
                                ROS1教程
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2022-12-22
                </div>
                

                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-check fa-fw"></i>更新日期:&nbsp;&nbsp;
                    2023-11-01
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    2k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    7 分
                </div>
                

                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">

        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/%E5%B1%8F%E5%B9%95%E5%BD%95%E5%88%B62022-12-23%20%E4%B8%8B%E5%8D%881.50.16.gif" alt="ROS1安装后运行小乌龟例程"></p>
<blockquote>
<p>作为<code>ROS1</code>系列教程中的第一篇文章，本文介绍了如何安装<code>ROS1</code></p>
</blockquote>
<h1 id="ROS1教程-1：ROS1安装"><a href="#ROS1教程-1：ROS1安装" class="headerlink" title="ROS1教程 1：ROS1安装"></a>ROS1教程 1：ROS1安装</h1><p>作为ROS1系列教程的第一篇文章，本文就将介绍如何在自己的电脑上安装<code>ROS1</code>。</p>
<h2 id="1-安装"><a href="#1-安装" class="headerlink" title="1. 安装"></a>1. 安装</h2><blockquote>
<p>注意，前面一篇文章中介绍了<code>ROS1</code>和<code>ROS2</code>的区别，<code>ROS1</code>最终的版本是<code>noetic</code>，对应的<code>Ubuntu</code>系统版本为<code>20.04</code>，<code>Ubuntu 22.04</code>及以后的版本都仅支持<code>ROS2</code>。</p>
<p><code>ROS1</code>系列教程文章都将在<code>Ubuntu 20.04</code>上编写、验证。</p>
</blockquote>
<h3 id="1-1-介绍"><a href="#1-1-介绍" class="headerlink" title="1.1 介绍"></a>1.1 介绍</h3><p><code>ROS1</code>安装大致的步骤如下：</p>
<ul>
<li>添加<code>ROS1</code>安装源</li>
<li>设置<code>key</code></li>
<li>下载、安装<code>ROS1</code></li>
<li>配置<code>ROS1</code>环境变量</li>
</ul>
<p>注意，本文适用于在<code>Ubuntu 20.04 LTS</code>上安装<code>ROS1 Noetic</code>版本。<code>ROS1</code>发行版通常是和<code>Ubuntu</code>发行版绑定的，例如在<code>Ubuntu 18.04</code>上只能安装<code>ROS1 Melodic</code>版本，而在<code>Ubuntu 20.04</code>上只能安装<code>ROS1 Noetic</code>版本。所以，如果要在其他版本的<code>Ubuntu</code>上安装其他版本的<code>ROS1</code>的话，大体流程和原理是相通的，但具体还得你根据自己的平台和安装的版本进行修改</p>
<h3 id="1-2-添加ROS1安装源"><a href="#1-2-添加ROS1安装源" class="headerlink" title="1.2 添加ROS1安装源"></a>1.2 添加<code>ROS1</code>安装源</h3><p>我们平时在手机上下载一个应用程序的时候，一般都是首先需要下载一个应用商城，然后我们就能够在应用商城内下载我们需要的软件。虽然说现在一般都是买到手机之后内置了一个应用商城，但并不影响我们举这个例子去理解。</p>
<p>一个应用商城中不可能有所有的软件，例如在<code>VIVO</code>应用商城中没有<code>Gmail</code>，如果我们想要安装<code>Gmail</code>，我们就得安装<code>Google</code>应用商城。</p>
<p>同样的道理，<code>Ubuntu</code>中使用的<code>APT</code>这个“软件商城”（术语：<code>包管理器</code>）中并不是所有软件都会有的，有的时候我们需要向其中添加软件源，这样<code>APT</code>包管理器才能知道去哪下载我们要安装的软件。</p>
<p><code>ROS1</code>本质上还是一个框架，因此我们依旧使用<code>APT</code>进行下载。但是<code>ROS1</code>并不在<code>APT</code>默认的下载源中，因此我们首先需要使用下面的命令添加<code>ROS1</code>的下载地址（术语：<code>安装源</code>）到<code>APT</code>中：</p>
<pre class="line-numbers language-bash"><code class="language-bash"><span class="token function">sudo</span> sh -c <span class="token string">'echo "deb http://packages.ROS1.org/ROS1/ubuntu <span class="token variable"><span class="token variable">$(</span>lsb_release -sc<span class="token variable">)</span></span> main" > /etc/apt/sources.list.d/ROS1-latest.list'</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>但是注意，上面的命令是添加官方的安装源，但是由于官方的服务器在国外，所以在国内下载就会很慢，因此国内更加推荐使用国内的镜像源。所谓镜像源指的其实就是国内的人花费比较长的时间从国外下载了之后上传到国内的服务器中供大家下载，并且保持和国外同步更新，从而加速了国内的下载。</p>
<p>国内可以使用清华源来安装：</p>
<pre class="line-numbers language-bash"><code class="language-bash"><span class="token function">sudo</span> sh -c <span class="token string">'. /etc/lsb-release &amp;&amp; echo "deb http://mirrors.tuna.tsinghua.edu.cn/ROS1/ubuntu/ <span class="token variable"><span class="token variable">`</span>lsb_release -cs<span class="token variable">`</span></span> main" > /etc/apt/sources.list.d/ROS1-latest.list'</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>也可以使用中科大源来安装：</p>
<pre class="line-numbers language-bash"><code class="language-bash"><span class="token function">sudo</span> sh -c <span class="token string">'. /etc/lsb-release &amp;&amp; echo "deb http://mirrors.ustc.edu.cn/ROS1/ubuntu/ <span class="token variable"><span class="token variable">`</span>lsb_release -cs<span class="token variable">`</span></span> main" > /etc/apt/sources.list.d/ROS1-latest.list'</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>我这里就直接用了清华源：</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/image-20221223002148873.png" alt="添加ROS1清华镜像源"></p>
<h3 id="1-3-添加Apt-Key"><a href="#1-3-添加Apt-Key" class="headerlink" title="1.3 添加Apt-Key"></a>1.3 添加<code>Apt-Key</code></h3><p>单纯添加软件的下载地址（安装源）可不行，因为网络上的攻击者可能会通过篡改地址、重定向等等技术来进行攻击，从而导致用户以为从安装源中下载的软件是<code>ROS1</code>，但是实际下载、安装的却是病毒。</p>
<p>因此，为了避免这种情况，在添加了安装源之后还需要安装源进行验证，以避免安装源指向的服务器被黑客篡改。具体验证的原理用官方发布的官方服务器的秘钥和本地添加的服务器（安装源）的秘钥进行比对、验证。</p>
<p>运行如下的命令：</p>
<pre class="line-numbers language-bash"><code class="language-bash"><span class="token function">sudo</span> apt-key adv --keyserver <span class="token string">'hkp://keyserver.ubuntu.com:80'</span> --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>这里因为我是已经添加、验证过了，所以显示的<code>Unchanged</code></p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/image-20221223002829306.png" alt="image-20221223002829306"></p>
<h3 id="1-4-下载、安装ROS1"><a href="#1-4-下载、安装ROS1" class="headerlink" title="1.4 下载、安装ROS1"></a>1.4 下载、安装<code>ROS1</code></h3><p>设置完了安装源之后，接下来就要下载、安装<code>ROS1</code>了。</p>
<p>首先更新一下</p>
<pre class="line-numbers language-bash"><code class="language-bash"><span class="token function">sudo</span> apt update
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>然后安装<code>ROS1</code></p>
<pre class="line-numbers language-bash"><code class="language-bash"><span class="token function">sudo</span> apt <span class="token function">install</span> ROS1-noetic-desktop-full
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>同样因为我已经安装过了，所以这里没有任何显示。一般正常情况安装可能需要30分钟左右。</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/image-20221223014741231.png" alt="下载、安装ROS1"></p>
<h3 id="1-5-配置环境变量"><a href="#1-5-配置环境变量" class="headerlink" title="1.5 配置环境变量"></a>1.5 配置环境变量</h3><p>最后，需要配置一下<code>ROS1</code>相关的环境变量，这样我们后面在编译程序的时候，能够找到<code>ROS1</code>的库。</p>
<p>对于<code>Bash</code>用户，使用下面的命令来添加环境变量</p>
<pre class="line-numbers language-bash"><code class="language-bash"><span class="token keyword">echo</span> <span class="token string">"source /opt/ROS1/noetic/setup.bash"</span> <span class="token operator">>></span> ~/.bashrc
<span class="token function">source</span> ~/.bashrc
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<p>对于<code>Zsh</code>用户，使用下面的命令来添加环境变量</p>
<pre class="line-numbers language-bash"><code class="language-bash"><span class="token keyword">echo</span> <span class="token string">"source /opt/ROS1/noetic/setup.zsh"</span> <span class="token operator">>></span> ~/.zshrc
<span class="token function">source</span> ~/.zshrc
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<h3 id="1-6-配置ROS1依赖"><a href="#1-6-配置ROS1依赖" class="headerlink" title="1.6 配置ROS1依赖"></a>1.6 配置ROS1依赖</h3><p>因为<code>ROS1</code>包含了非常多的软件包，而我们上面在下载的时候只是下载了<code>ROS1</code>最基础的组件，还有更多的组件是我们用到了才会去下载，例如我们的机器人中有激光雷达的话，我们才会去下载激光雷达相关的组件。因此，这一步就是先配置ROS1各个组件之间的依赖关系。</p>
<p><code>ROS1</code>中专门有一个<code>rosdep</code>，来配置<code>ROS1</code>的各种组件之间的依赖关系。</p>
<p>首先安装构建依赖的相关工具：</p>
<pre class="line-numbers language-bash"><code class="language-bash"><span class="token function">sudo</span> apt <span class="token function">install</span> python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>然后安装<code>rosdep</code></p>
<pre class="line-numbers language-bash"><code class="language-bash"><span class="token function">sudo</span> apt <span class="token function">install</span> python3-rosdep
<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre>
<p>安装完了<code>rosdep</code>之后，利用<code>rosdep</code>来初始化依赖</p>
<pre class="line-numbers language-bash"><code class="language-bash"><span class="token function">sudo</span> rosdep init
rosdep update
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<p>配置成功的话，会显示下面的信息</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/image-20221223123406529.png" alt="配置成功" style="zoom: 25%;"></p>
<p>但是上面这两步经常出错，因为这两步都会从<code>Github</code>去下载配置信息，所以很容易失败</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/noetic%E5%BC%82%E5%B8%B8%E6%8F%90%E7%A4%BA.png" alt="img"></p>
<p>为此，要么科学上网，然后给命令行挂代理，从而避免下载失败，要么就用<code>rosdepc</code>。</p>
<p><code>rosdepc</code>的原理就是，因为<code>rosdep</code>是从<code>Github</code>上去下载配置信息。所以如果我们能够在国内建立一个镜像源，然后让<code>rosdep</code>从国内的镜像源中下载依赖就可以解决问题了。</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/image-20221223123705192.png" alt="Github上的ROS1配置信息" style="zoom: 25%;"></p>
<p>所以我们就可以使用<code>rosdepc</code>这个使用国内镜像源的依赖工具。</p>
<p>首先安装<code>rosdepc</code></p>
<pre class="line-numbers language-bash"><code class="language-bash"><span class="token function">sudo</span> pip <span class="token function">install</span> rosdepc  
<span class="token function">sudo</span> pip3 <span class="token function">install</span> rosdepc
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<p>然后使用<code>rosdepc</code>来更新依赖</p>
<pre class="line-numbers language-bash"><code class="language-bash"><span class="token function">sudo</span> rosdepc init
rosdepc update
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>
<h2 id="2-测试"><a href="#2-测试" class="headerlink" title="2. 测试"></a>2. 测试</h2><p>安装完了之后我们要测试一下<code>ROS1</code>是否能够正常运行。为此，我们运行<code>ROS1</code>内置的程序</p>
<p>下面的命令要使用三个命令行来运行，因为一个机器人，想要正常运行的话，肯定是需要多个不同的进程相互配合的，例如：有的进程负责视觉，有的进程负责运动，有的进程负责定位和导航。而<code>ROS1</code>就是负责统一去管理这些进程的框架。</p>
<p><code>ROS1</code>中将每个进程抽象为一个节点，而将各个进程之间的数据交互和配合视为节点之间的链接。从而实现了用节点图来描述机器人的正常运行状态。</p>
<p>我们这里没有真实的机器人，所以我们主要测试看看我们安装的<code>ROS1</code>能否正常运行启动多个节点，构成节点图。开三个终端，分别运行下面的命令：</p>
<pre class="line-numbers language-bash"><code class="language-bash">roscore            <span class="token comment" spellcheck="true"># 启动ROS1管理器</span>
rosrun turtlesim turtlesim_node            <span class="token comment" spellcheck="true"># 启动第一个节点，GUI节点</span>
rosrun turtlesim turtle_teleop_key            <span class="token comment" spellcheck="true"># 启动第二个节点，键盘监听节点</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>
<p>事实上启动了<code>GUI</code>节点之后，就会显示GUI界面了，但是此时我们没有办法控制窗口中的乌龟。直到我们启动了键盘监听节点之后，我们才能够控制乌龟。</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/image-20221223133452281.png" alt="image-20221223133452281"></p>
<p>在启动了<code>GUI</code>节点和键盘监听节点后，我们要使用鼠标点击键盘监听结点的窗口，即聚焦到键盘监听结点窗口上，而后按下键盘上下左右键来控制乌龟运动</p>
<p><img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/%E5%B1%8F%E5%B9%95%E5%BD%95%E5%88%B62022-12-23%20%E4%B8%8B%E5%8D%881.50.16.gif" alt="屏幕录制2022-12-23 下午1.50.16"></p>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">Jack Wang</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://jackwang0107.github.io/2022/12/22/ros-jiao-cheng-1-ros-an-zhuang/">https://jackwang0107.github.io/2022/12/22/ros-jiao-cheng-1-ros-an-zhuang/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/about" target="_blank">Jack Wang</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/ROS1/">
                                    <span class="chip bg-color">ROS1</span>
                                </a>
                            
                                <a href="/tags/ROS1%E6%95%99%E7%A8%8B/">
                                    <span class="chip bg-color">ROS1教程</span>
                                </a>
                            
                                <a href="/tags/ROS1%E5%AE%89%E8%A3%85/">
                                    <span class="chip bg-color">ROS1安装</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.png" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.jpg" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2022/12/22/ros-jiao-cheng-0-ros-jie-shao/">
                    <div class="card-image">
                        
                        <img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/image-20221222234619457.png" class="responsive-img" alt="ROS教程 0：ROS介绍">
                        
                        <span class="card-title">ROS教程 0：ROS介绍</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            本文是ROS系列教程的前言，介绍了什么是ROS、ROS的发展历史以及ROS1和ROS2的区别
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2022-12-22
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/ROS%E6%95%99%E7%A8%8B/" class="post-category">
                                    ROS教程
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/ROS/">
                        <span class="chip bg-color">ROS</span>
                    </a>
                    
                    <a href="/tags/ROS%E6%95%99%E7%A8%8B/">
                        <span class="chip bg-color">ROS教程</span>
                    </a>
                    
                    <a href="/tags/ROS%E5%AE%89%E8%A3%85/">
                        <span class="chip bg-color">ROS安装</span>
                    </a>
                    
                    <a href="/tags/ROS1/">
                        <span class="chip bg-color">ROS1</span>
                    </a>
                    
                    <a href="/tags/ROS1%E6%95%99%E7%A8%8B/">
                        <span class="chip bg-color">ROS1教程</span>
                    </a>
                    
                    <a href="/tags/ROS1%E5%AE%89%E8%A3%85/">
                        <span class="chip bg-color">ROS1安装</span>
                    </a>
                    
                    <a href="/tags/ROS2/">
                        <span class="chip bg-color">ROS2</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2022/12/02/vscode-diao-shi-c-c-shi-yong-gdb-ming-ling/">
                    <div class="card-image">
                        
                        <img src="https://jack-1307599355.cos.ap-shanghai.myqcloud.com/image-20221223173532849.png" class="responsive-img" alt="VSCode调试C/C++技巧：使用GDB命令">
                        
                        <span class="card-title">VSCode调试C/C++技巧：使用GDB命令</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            本文介绍了使用VSCode来调试C/C++工程的技巧：使用GDB命令
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2022-12-02
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/VSCode%E8%B0%83%E8%AF%95C-C/" class="post-category">
                                    VSCode调试C/C++
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/%E6%9D%82%E9%A1%B9/">
                        <span class="chip bg-color">杂项</span>
                    </a>
                    
                    <a href="/tags/VSCode/">
                        <span class="chip bg-color">VSCode</span>
                    </a>
                    
                    <a href="/tags/tasks-json/">
                        <span class="chip bg-color">tasks.json</span>
                    </a>
                    
                    <a href="/tags/launch-json/">
                        <span class="chip bg-color">launch.json</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('120')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE' || selection.getRangeAt(0).commonAncestorContainer.nodeName === 'CODE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + '来源: JackWang&#39;s Blog<br />'
            + '文章作者: Jack Wang<br />'
            + '文章链接: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>


<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('2'),
            headingSelector: 'h1, h2, h3, h4, h5, h6'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h1, h2, h3, h4, h5, h6').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    

    <div class="container row center-align"
         style="margin-bottom: 15px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2021-2023</span>
            
            <a href="/about" target="_blank">Jack Wang</a>
            <!-- |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a> -->
            <!-- |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a> -->
            <br>
            
                &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                        class="white-color">603.8k</span>
            
            
            
                
            
            
                <span id="busuanzi_container_site_pv">
                &nbsp;|&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;
                    <span id="busuanzi_value_site_pv" class="white-color"></span>
            </span>
            
            
                <span id="busuanzi_container_site_uv">
                &nbsp;|&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;
                    <span id="busuanzi_value_site_uv" class="white-color"></span>
            </span>
            
            <br>

            <!-- 运行天数提醒. -->
            
                <span id="sitetime"> Loading ...</span>
                <script>
                    var calcSiteTime = function () {
                        var seconds = 1000;
                        var minutes = seconds * 60;
                        var hours = minutes * 60;
                        var days = hours * 24;
                        var years = days * 365;
                        var today = new Date();
                        var startYear = "2021";
                        var startMonth = "11";
                        var startDate = "12";
                        var startHour = "0";
                        var startMinute = "0";
                        var startSecond = "0";
                        var todayYear = today.getFullYear();
                        var todayMonth = today.getMonth() + 1;
                        var todayDate = today.getDate();
                        var todayHour = today.getHours();
                        var todayMinute = today.getMinutes();
                        var todaySecond = today.getSeconds();
                        var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                        var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                        var diff = t2 - t1;
                        var diffYears = Math.floor(diff / years);
                        var diffDays = Math.floor((diff / days) - diffYears * 365);

                        // 区分是否有年份.
                        var language = 'zh-CN';
                        if (startYear === String(todayYear)) {
                            document.getElementById("year").innerHTML = todayYear;
                            var daysTip = 'This site has been running for ' + diffDays + ' days';
                            if (language === 'zh-CN') {
                                daysTip = '本站已运行 ' + diffDays + ' 天';
                            } else if (language === 'zh-HK') {
                                daysTip = '本站已運行 ' + diffDays + ' 天';
                            }
                            document.getElementById("sitetime").innerHTML = daysTip;
                        } else {
                            document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                            var yearsAndDaysTip = 'This site has been running for ' + diffYears + ' years and '
                                + diffDays + ' days';
                            if (language === 'zh-CN') {
                                yearsAndDaysTip = '本站已运行 ' + diffYears + ' 年 ' + diffDays + ' 天';
                            } else if (language === 'zh-HK') {
                                yearsAndDaysTip = '本站已運行 ' + diffYears + ' 年 ' + diffDays + ' 天';
                            }
                            document.getElementById("sitetime").innerHTML = yearsAndDaysTip;
                        }
                    }

                    calcSiteTime();
                </script>
            
            <br>
            
                <span id="icp"><img src="/medias/icp.png"
                                    style="vertical-align: text-bottom;"/>
                <a href="https://beian.miit.gov.cn" target="_blank">陕ICP备2021014294号-1</a>
            </span>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/jackwang0108" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:2232123545@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=2232123545" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 2232123545" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    

    
        
        <script type="text/javascript">
            // 只在桌面版网页启用特效
            var windowWidth = $(window).width();
            if (windowWidth > 768) {
                document.write('<script type="text/javascript" src="/libs/others/sakura.js"><\/script>');
            }
        </script>
    

    <!-- 雪花特效 -->
    

    <!-- 鼠标星星特效 -->
    

     
        <script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
        <script src="/libs/others/TencentCaptcha.js"></script>
        <button id="TencentCaptcha" data-appid="xxxxxxxxxx" data-cbfn="callback" type="button" hidden></button>
    

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    <!--腾讯兔小巢-->
    
    

    

    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
